﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace QuanLyDiemSinhVien.Manager
{
    public class TeacherManager
    {
        #region ATTRIBUTES
        private static TeacherData _data;
        private static string m_error;
        #endregion

        #region CONSTRUCTORS
        static TeacherManager()
        {
            _data = new TeacherData(Constans.ConnectionString);
            m_error = "";
        }
        #endregion

        #region PROPERTIES
        public static string ErrorMessage
        {
            get
            {
                return m_error;
            }
        }
        #endregion

        #region METHODS

        public static int Insert(string studentName, int classId, int examRoomId, bool status)
        {
            m_error = "";
            try
            {
                object[] values = { studentName, classId, examRoomId, DateTime.Now, true };
                return _data.Insert(values);
            }
            catch (Exception ex) { return 0; }
        }

        public static bool Update()
        {
            m_error = "";
            try
            {
                object[] values = { };
                return _data.Update(values);
            }
            catch (Exception ex)
            {
                m_error = ex.Message;
                return false;
            }
        }

        public static bool Delete(long studentId)
        {
            m_error = "";
            try
            {
                object[] values = { studentId };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                m_error = ex.Message;
                return false;
            }
        }

        public static DataTable Select(object[] studentId)
        {
            m_error = "";
            try
            {
                return _data.Select(studentId);
            }
            catch (Exception ex)
            {
                m_error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectAll()
        {
            m_error = "";
            try
            {
                return _data.SelectAll();
            }
            catch (Exception ex)
            {
                m_error = ex.Message;
                return null;
            }
        }

        public static DataTable Search(string condition, object[] values)
        {
            m_error = "";
            try
            {
                return _data.Search(condition, values);
            }
            catch (Exception ex)
            {
                m_error = ex.Message;
                return null;
            }
        }

        public static object Login(string userName, string password)
        {
            object[] values = { userName, password };
            return _data.Login(values);
        }

        public static bool CheckExistsUserInfo(int studentId)
        {
            m_error = "";
            try
            {
                return _data.CheckExistsUserInfo(studentId);
            }
            catch (Exception ex) { return false; }
        }

        #endregion
    }
}
